import storejs from 'storejs'
import iframePostMessage from '@/plugins/iframePostMessage.js'
const state = {
    access: {
        access_token: ""
    },
    testMapState: "我是mapState"
}

// getters
const getters = {
    getToken: state => {
        return state.access.access_token || storejs.get('token');
    }
}

// actions
const actions = {
    updateToken({ state, commit }, access_token) {
        if (state.access.access_token != access_token) {
            commit('updateAccessToken', access_token)
            storejs.set('token', access_token)
            iframePostMessage.saveToken(access_token)
        }
    }
}

// mutations
const mutations = {
    updateAccessToken(state, access_token) {
        state.access.access_token = access_token
    },
}

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}